package com.naiterui.ehp.bs.consult.repository;

import com.naiterui.common.repository.core.BaseJpaRepository;
import com.naiterui.ehp.bp.domain.DrVideoConsult;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * 医生视频咨询收费持久层
 *
 * @author luao
 * @date 2021/2/25 2:39 下午
 **/
@Repository
public interface DrVideoConsultRepository extends BaseJpaRepository<DrVideoConsult, Long> {

    DrVideoConsult findFirstByPatientIdAndDoctorIdOrderByCreatedAtDesc(Long patientId, Long doctorId);

    DrVideoConsult findFirstByOrderSn(String orderSn);

    DrVideoConsult findByRoomId(Integer roomId);

    Page<DrVideoConsult> findByPatientIdAndVideoConsultStatusInOrderByChangedAtDesc(Long patientId, List<Integer> consultStatus, Pageable pageable);

    Page<DrVideoConsult> findByPatientIdAndDoctorIdAndVideoConsultStatusInOrderByChangedAtDesc(Long patientId,Long doctorId, List<Integer> consultStatus, Pageable pageable);

    Page<DrVideoConsult> findByDoctorIdAndVideoConsultStatusInOrderByIsTreatDescChangedAtDesc(Long doctorId, List<Integer> videoConsultStatusList, Pageable pageable);

    List<DrVideoConsult> findByDoctorIdAndVideoConsultStatus(Long doctorId, Integer videoConsultStatusList);

    @Query(value = "select COUNT(id) from DrVideoConsult where doctorId = ?1 AND videoConsultStatus <> "
            + DrVideoConsult.VIDEO_CONSULT_STATUS_CANCEL)
    Integer findCountByDoctorId(Long doctorId);

    List<DrVideoConsult> findByDoctorId(Long doctorId);

    List<DrVideoConsult> findByConsultTimeBetweenAndVideoConsultStatusIn(Date start, Date end, List<Integer> status);

    Page<DrVideoConsult> findByInquirerIdInAndVideoConsultStatus(List<Long> inquirerId, Integer consultStatus,
                                                                 Pageable pageable);

    List<DrVideoConsult> findByIdIn(Collection<Long> idList);

}
